﻿Public Class TypeImageConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If Not TypeOf value Is TreeNodes.NodeTypes Then Return Nothing

        Dim result As DrawingBrush = Nothing
        Dim resImage As Object = Nothing
        Dim inputValue = [Enum].Parse(GetType(TreeNodes.NodeTypes), value.ToString)
        Select Case inputValue
            Case TreeNodes.NodeTypes.Namespace : resImage = My.Application.Resources("ISNamespace")
            Case TreeNodes.NodeTypes.Interface : resImage = My.Application.Resources("ISInterface")
            Case TreeNodes.NodeTypes.Class : resImage = My.Application.Resources("ISClass")
            Case TreeNodes.NodeTypes.Method : resImage = My.Application.Resources("ISMethod")
            Case TreeNodes.NodeTypes.Property : resImage = My.Application.Resources("ISProperty")
            Case TreeNodes.NodeTypes.Field : resImage = My.Application.Resources("ISField")
            Case TreeNodes.NodeTypes.Enum : resImage = My.Application.Resources("ISEnum")
            Case TreeNodes.NodeTypes.ValueType : resImage = My.Application.Resources("ISStructure")
            Case TreeNodes.NodeTypes.Event : resImage = My.Application.Resources("ISEvent")
            Case TreeNodes.NodeTypes.Primitive
            Case Else
        End Select

        If resImage IsNot Nothing Then
            result = New DrawingBrush() With {
                .Drawing = New ImageDrawing(resImage, New Rect(0, 0, 16, 16))
            }
        End If
        Return result
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException
    End Function

End Class
